package com.jie.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jie.dto.HealthInfoDTO;
import com.jie.entity.BodyDimension;
import com.jie.entity.HealthInfo;
import com.jie.mapper.BodyDimensionMapper;
import com.jie.mapper.HealthInfoMapper;
import com.jie.service.IHealthInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户健康数据信息表 服务实现类
 * </p>
 *
 * @author jie
 * @since 2024-04-20
 */
@Service
public class HealthInfoServiceImpl extends ServiceImpl<HealthInfoMapper, HealthInfo> implements IHealthInfoService {

    @Autowired
    private BodyDimensionMapper bodyDimensionMapper;
    @Override
    public HealthInfoDTO selectUserHeadlthById(Integer userId) {
        HealthInfoDTO healthInfoDTO = new HealthInfoDTO();
        //获取当前用户的健康信息
        HealthInfo userHealthInfo = this.baseMapper.selectOne(new LambdaQueryWrapper<HealthInfo>().eq(HealthInfo::getUserId, userId));
        //获取身体维度信息
        BodyDimension bodyDimensionInfo = bodyDimensionMapper.selectById(userHealthInfo.getBodyDimensionId());
        //封装成DTO返回
        BeanUtils.copyProperties(userHealthInfo,healthInfoDTO);
        BeanUtils.copyProperties(bodyDimensionInfo,healthInfoDTO);
        return healthInfoDTO;
    }
}
